#include "window_qrcode.h"


static void my_event_cb(lv_event_t * event)
{
	
	//printf("LV_EVENT_LONG_PRESSED\r\n");
	#if 1
	lv_dir_t  dir = lv_indev_get_gesture_dir(lv_indev_get_act());//获得手势的方向
	
		//判断当前的对象
	  lv_obj_t * obj = lv_event_get_target(event);
	
	  lv_indev_t * indev = lv_indev_get_act(); //获取当前的坐标
    if(indev == NULL)  return;
	if(LV_DIR_RIGHT  == dir)  
	{
		lv_obj_del(obj);  //删除当前对象
		printf("LV_DIR_RIGHT\r\n");
	}else if(LV_DIR_LEFT  == dir)
	{
	  printf("LV_DIR_LEFT\r\n");
	}
	
  #endif
	
}


void QRcode_init()
{
	 lv_obj_t* obj =lv_obj_create(lv_scr_act());	  //创建屏幕对象
	 lv_obj_set_style_bg_color(obj, lv_color_make(0,0,0), 0);//设置背景颜色为黑色
	 lv_obj_set_size(obj, LV_HOR_RES_MAX, LV_VER_RES_MAX);
	
	  static lv_style_t lv_style;              //外部样式
    lv_style_init(&lv_style);           // 初始化按钮样式
	  //lv_style_set_radius(&lv_style, 20); // 设置样式圆角弧度
	  //lv_obj_set_style_bg_color(list1, lv_color_make(0,0,0), 0);//设置背景颜色为黑色
	  lv_obj_set_scrollbar_mode(obj, LV_SCROLLBAR_MODE_OFF);  //取消滚动条显示
    //lv_obj_set_style_bg_opa(list1,LV_OPA_60,0);               //设置透明度
		lv_style_set_bg_color(&lv_style,lv_color_make(0,0,0));
	  lv_style_set_text_align(&lv_style,LV_TEXT_ALIGN_LEFT);
		
		lv_style_set_text_color(&lv_style,lv_color_make(0xff,0xff,0xff));
		lv_style_set_text_color_filtered(&lv_style,lv_color_make(0xff,0,0));
	  lv_style_set_pad_all(&lv_style,0); //铺满整个布局
  	lv_style_set_border_color(&lv_style,lv_color_make(0,0,0)); //设置边框颜色
	  lv_obj_add_style(obj, &lv_style, 0);
	
   lv_color_t bg_color = lv_palette_lighten(LV_PALETTE_LIGHT_BLUE, 5);
    lv_color_t fg_color = lv_palette_darken(LV_PALETTE_BLUE, 5);

    lv_obj_t * qr = lv_qrcode_create(obj, 100, fg_color, bg_color/*lv_color_hex3(0x33f), lv_color_hex3(0xeef)*/);

 

    /*Set data*/
    const char * data = "https://www.freqchip.com/";
    lv_qrcode_update(qr, data, strlen(data));
    lv_obj_center(qr);

    /*Add a border with bg_color*/
    lv_obj_set_style_border_color(qr, bg_color, 0);
    lv_obj_set_style_border_width(qr, 10, 0);

  //显示标题
	lv_obj_t* label = lv_label_create(obj); // 创建一个标签，用于显示滑块的滑动值
	if (label != NULL)
	{
		
				lv_label_set_recolor(label, true);                        /*Enable re-coloring by commands in the text*/
				lv_label_set_text_fmt(label, "#ffffff Qrcode\n #");
				lv_obj_align(label, LV_ALIGN_TOP_MID,0,20);
	}

    lv_obj_add_event_cb(obj,my_event_cb,LV_EVENT_PRESSING,NULL);   //添加对象回调函数
}
